package com.navinfo.tripanalysis.common.arithmetic;

import com.navinfo.tripanalysis.common.arithmetic.annotation.Arithmetic;
import com.navinfo.tripanalysis.common.arithmetic.common.CommonData;
import com.navinfo.tripanalysis.common.arithmetic.common.OuterStatisticData;
import com.navinfo.tripanalysis.common.arithmetic.common.OuterStatisticExtendedData;
import com.navinfo.tripanalysis.common.arithmetic.custom.VarRangeTorqueUrea;
import com.navinfo.tripanalysis.common.arithmetic.enums.RangeTorqueEnum;
import com.navinfo.tripanalysis.common.arithmetic.manager.AbstractArithmetic;
import com.navinfo.tripanalysis.common.util.ArithmeticUtils;

/**
 * 东风
 * 发动机扭矩区间尿素消耗算法<br/>
 * 输出：统计
 *
 * @author liudong
 */
@Arithmetic(name = "发动机扭矩区间尿素消耗")
public class RangeTorqueUrea_DF extends AbstractArithmetic<VarRangeTorqueUrea> {

    @Override
    public void calculate() {
        logger.debug("进入发动机扭矩区间尿素消耗算法.");
        CommonData commonData = getCommonData();
        int actualEnginePercentTor = commonData.getEngineOutputTorque();

        if (!RangeTorqueEnum.RANGE_VALID.getRange().contains(actualEnginePercentTor)) {
            return;
        }

        VarRangeTorqueUrea var = getObj();

        int urea = ArithmeticUtils.massToVolume(commonData.getUreaInjection(), commonData.getAtmosphericTem());
        if (urea == 0) {
            return;
        }
        //累加相应扭矩区间的统计变量
        if (RangeTorqueEnum.RANGE_0.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent0(urea);
        } else if (RangeTorqueEnum.RANGE_10.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent10(urea);
        } else if (RangeTorqueEnum.RANGE_20.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent20(urea);
        } else if (RangeTorqueEnum.RANGE_30.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent30(urea);
        } else if (RangeTorqueEnum.RANGE_40.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent40(urea);
        } else if (RangeTorqueEnum.RANGE_50.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent50(urea);
        } else if (RangeTorqueEnum.RANGE_60.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent60(urea);
        } else if (RangeTorqueEnum.RANGE_70.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent70(urea);
        } else if (RangeTorqueEnum.RANGE_80.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent80(urea);
        } else if (RangeTorqueEnum.RANGE_90.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent90(urea);
        } else if (RangeTorqueEnum.RANGE_99.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent99(urea);
        } else if (RangeTorqueEnum.RANGE_100.getRange().contains(actualEnginePercentTor)) {
            var.addTorquePercent100(urea);
        }

        logger.debug("离开发动机扭矩区间尿素消耗算法.");
    }

    @Override
    public void collect(OuterStatisticData statisticDataOut) {
        VarRangeTorqueUrea var = getObj();

        OuterStatisticExtendedData extendedData = statisticDataOut.getExtendedData();
        extendedData.setTorque0Urea(var.getTorquePercent0());
        extendedData.setTorque10Urea(var.getTorquePercent10());
        extendedData.setTorque20Urea(var.getTorquePercent20());
        extendedData.setTorque30Urea(var.getTorquePercent30());
        extendedData.setTorque40Urea(var.getTorquePercent40());
        extendedData.setTorque50Urea(var.getTorquePercent50());
        extendedData.setTorque60Urea(var.getTorquePercent60());
        extendedData.setTorque70Urea(var.getTorquePercent70());
        extendedData.setTorque80Urea(var.getTorquePercent80());
        extendedData.setTorque90Urea(var.getTorquePercent90());
        extendedData.setTorque99Urea(var.getTorquePercent99());
        extendedData.setTorque100Urea(var.getTorquePercent100());
    }
}
